package com.start.common.dataImport;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

@Data
public class DataImportEntity {
    @Schema(name = "文件路径")
    private String filePath;
    @Schema(name = "上传标记")
    private String uploadKey;
    @Schema(name = "上传名称")
    private String uploadName;
     @Schema(name="是否异步")
    private Boolean isSync = true;

    public List<String> getFilePath() {
        if (StringUtils.isEmpty(filePath)) {
            return null;
        }
        JSONArray jsonArray = JSONArray.parseArray(filePath);
        List<String> paths = new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if (!jsonObject.containsKey("value" ) || StringUtils.isEmpty(jsonObject.getString("value" ))) {
                continue;
            }
            paths.add(jsonObject.getString("value" ));
        }
        List<String> collect = paths.stream().distinct().collect(Collectors.toList());
        return collect;
    }
}
